package schoolsource.gui;

import java.util.HashMap;

import schoolsource.model.Container;

public class ImageContent extends Content {
//    private String text;
    private Container[] contents;
    private String[] accessorNames;
    private HashMap gifMap;
    private String defaultGif;

    protected ImageContent() {

    }

    public ImageContent(Container[] container, String[] newAccessorNames, HashMap newGifMap, String newDefaultGif) {
        contents = container;
        accessorNames = newAccessorNames;
        gifMap = newGifMap;
        defaultGif = newDefaultGif;
    }

    public int size() {
        return contents.length;
    }

    public String getRow(int index, int width) {
        Object returnItem = contents[index];
        try {
            for (int i = 0; i < accessorNames.length; ++i) {
                returnItem = returnItem.getClass().getMethod(accessorNames[i], new Class[] {}).invoke(returnItem, new Object[] {});
            }
        }
        catch (Exception e) {
        }

        String gifName = gifMap.get(returnItem.toString().toUpperCase()).toString();
        if (gifName == null) {
            gifName = defaultGif;
        }
        return "<IMG SRC=\"" + gifName.toString() + "\" width=\"15\";border=\"0\">";
    }

    public String getText(int index) {
        return "";
    }

    public boolean useDiv() {
        return false;
    }
}